﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RG.Common.Provider;
using NHibernate.Criterion;
using NHibernate.Mapping.Attributes;
using RG.Consts;
using RealtorGuide.DAO;

namespace RG.DAO
{
    public interface IManagerDAO
    {
        ManagerDAOObj Get(int id);
        int Put(ManagerDAOObj obj);
        List<ManagerDAOObj> List(ManagersQueryParams param);
    }

     public class ManagerDAO : TransactionService<RGProvider>, IManagerDAO
    {
        public ManagerDAOObj Get(int id)
        {
            return DAOSession.Get<ManagerDAOObj>(id);
        }

        public int Put(ManagerDAOObj obj)
        {
            DAOSession.Put(obj);
            return obj.Id;
        }

        public List<ManagerDAOObj> List(ManagersQueryParams param)
        {
            var q = DetachedCriteria.For<ManagerDAOObj>();

            return DAOSession.List<ManagerDAOObj>(q).ToList();
        }
    }

    /// <summary>
    /// Договор хранения
    /// </summary>
    [HibernateMapping]
    [Class(Table = "Managers")]
    public class ManagerDAOObj : IManager
    {
        /// <summary>
        /// Идентификатор
        /// </summary>
        [Id(-4, Name = "Id")]
        [Column(-3, Name = "C_Manager")]
        [Generator(-2, Class = "sequence")]
        [Param(-1, Name = "sequence", Content = "GEN_Managers")]
        public virtual int Id { get; set; }
        /// <summary>
        /// ФИО
        /// </summary>
        [Property]
        public virtual string FIO { get; set; }

        /// <summary>
        /// Телефон
        /// </summary>
        [Property]
        public virtual string Phone { get; set; }

        /// <summary>
        /// Заметки
        /// </summary>
        [Property]
        public virtual string Notes { get; set; }
      
    }

}
